<template>
  <!--上清所结算缴费界面-->
  <div style="margin-right:50px;">
    <el-form
      :model="form"
      status-icon
      ref="form"
      label-width="140px"
      class="demo-ruleForm"
      style="margin-top: 50px;"
      size="mini">
      <el-row>
        <el-col :span="8">
          <el-form-item
            label="交易日期:"
            prop="tradedate"
            :rules="rules.tradedate"
          >
            <el-date-picker
              v-model="form.tradedate"
              type="date"
              class="venus-input-middle venus-input-date"
              placeholder="请输入起始日期"
              value-format="yyyyMMdd"
              @change="portfol_change_fnc"
            />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item
            label="缴费范围:"
            prop="startdate"
            :rules="rules.startdate"
          >
            <el-date-picker
              v-model="form.startdate"
              type="date"
              class="venus-input-middle venus-input-date"
              placeholder="请输入起始日期"
              value-format="yyyyMMdd"
            /> -
            <el-date-picker
              v-model="form.enddate"
              type="date"
              class="venus-input-middle venus-input-date"
              placeholder="请输入起始日期"
              value-format="yyyyMMdd"
            />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <!-- prop,:rules必须一起写 -->
          <el-form-item
            label="账户维护费:"
            prop="Bill_maintenance"
            :rules="rules.Bill_maintenance"
          >
            <el-input v-model="form.Bill_maintenance" type="number" @change="getSJSJF" />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <!-- prop,:rules必须一起写 -->
          <el-form-item
            label="质押式回购（单券种）:"
            prop="Pledge_style_Repo1"
            :rules="rules.Pledge_style_Repo1"
            :label-width="'180px'"
          >
            <el-input v-model="form.Pledge_style_Repo1" type="number" @change="getSJSJF" />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <!-- prop,:rules必须一起写 -->
          <el-form-item
            label="质押式回购（多券种）:"
            prop="Pledge_style_Repo2"
            :rules="rules.Pledge_style_Repo2"
            :label-width="'180px'"
          >
            <el-input v-model="form.Pledge_style_Repo2" type="number" @change="getSJSJF" />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <!-- prop,:rules必须一起写 -->
          <el-form-item
            label="买断式回购:"
            prop="Outright_Repo"
            :rules="rules.Outright_Repo"
          >
            <el-input v-model="form.Outright_Repo" type="number" @change="getSJSJF" />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <!-- prop,:rules必须一起写 -->
          <el-form-item
            label="债券买卖:"
            prop="bond_deal2"
            :rules="rules.bond_deal2"
          >
            <el-input v-model="form.bond_deal2" type="number" @change="getSJSJF" />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <!-- prop,:rules必须一起写 -->
          <el-form-item
            label="总费用:"
            prop="total_cost2"
            :rules="rules.total_cost2"
          >
            <el-input v-model="form.total_cost2" type="number" disabled />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <!-- prop,:rules必须一起写 -->
          <el-form-item
            label="备注:"
            prop="remark"
          >
            <el-input v-model="form.remark" />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item
            label="产品组合:"
            prop="t8_sys_portfol_id"
            :rules="rules.t8_sys_portfol_id"
          >
            <el-select
              v-model="form.t8_sys_portfol_id"
              placeholder="--请选择--"
              filterable
              clearable
              @change="portfol_change_fnc"
            >
              <el-option
                v-for="value in dict.t8_port_info_id"
                :key="value.value"
                :label="value.dtype + '-' + value.text"
                :value="value.value"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item
            label="产品/SPV:"
            prop="t8_prod_info_id"
            :rules="rules.t8_prod_info_id"
          >
            <el-select
              v-model="form.t8_prod_info_id"
              placeholder="--请选择--"
              filterable
              clearable
              @change="prod_change_fnc"
            >
              <el-option
                v-for="value in dict.t8_prod_info_id"
                :key="value.value"
                :label="value.code + '-' + value.text"
                :value="value.value"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <!-- prop,:rules必须一起写 -->
          <el-form-item
            label="产品/SPV余额(元):"
            prop="prod_principalbln"
          >
            <el-input v-model="form.prod_principalbln" type="number" disabled />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item
            label="资金账号:"
            prop="account_code"
            :rules="rules.account_code"
          >
            <el-select
              v-model="form.account_code"
              placeholder="--请选择--"
              filterable
              clearable
              @change="selectAccount_change_fnc"
            >
              <el-option
                v-for="value in dict.account_code"
                :key="value.account_code"
                :label="value.account_code"
                :value="value.account_code"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <!-- prop,:rules必须一起写 -->
          <el-form-item
            label="资金账户名称:"
            prop="account_name"
            :rules="rules.account_name"
          >
            <el-input v-model="form.account_name" disabled />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <!-- prop,:rules必须一起写 -->
          <el-form-item
            label="开户行名称:"
            prop="opening_account_name"
            :rules="rules.opening_account_name"
          >
            <el-input v-model="form.opening_account_name" disabled />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <!-- prop,:rules必须一起写 -->
          <el-form-item
            label="开户行行号:"
            prop="opening_account_num"
          >
            <el-input v-model="form.opening_account_num" disabled />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <!-- prop,:rules必须一起写 -->
          <el-form-item
            label="收款账号:"
            prop="income_account_code"
            :rules="rules.income_account_code"
          >
            <el-input v-model="form.income_account_code" />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <!-- prop,:rules必须一起写 -->
          <el-form-item
            label="收款户名:"
            prop="income_account_name"
            :rules="rules.income_account_name"
          >
            <el-input v-model="form.income_account_name" />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <!-- prop,:rules必须一起写 -->
          <el-form-item
            label="收款开户行名称:"
            prop="income_opening_account_num"
            :rules="rules.income_opening_account_num"
          >
            <el-input v-model="form.income_opening_account_num" />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <!-- prop,:rules必须一起写 -->
          <el-form-item
            label="收款开户行行号:"
            prop="income_opening_account_name"
            :rules="rules.income_opening_account_name"
          >
            <el-input v-model="form.income_opening_account_name" />
          </el-form-item>
        </el-col>
        <el-col :xs="0" :sm="0" :md="0">
          <el-input v-model="form.prod_establish_date" :disabled="true" type="hidden" />
          <el-input v-model="form.prod_end_date" :disabled="true" type="hidden" />
          <el-input v-model="form.prod_tag_type" :disabled="true" type="hidden" />
          <el-input v-model="form.trustee_account_code" :disabled="true" type="hidden" />
          <el-input v-model="form.trustee_account_name" :disabled="true" type="hidden" />
          <el-input v-model="form.trustee_opening_account_num" :disabled="true" type="hidden" />
          <el-input v-model="form.trustee_opening_account_name" :disabled="true" type="hidden" />
          <el-input v-model="form.prod_tag_type" :disabled="true" type="hidden" />
          <el-input v-model="form.security_code" :disabled="true" type="hidden" />
        </el-col>
      </el-row>
      <div style="text-align:center">
        <el-button type="success" @click="settlement3" >提交</el-button>
        <el-button type="info" @click="reset">重置</el-button>
      </div>
    </el-form>
  </div>
</template>
<script>

  import request from '../../../../../../utils/request'

  export default {
    data() {
      return {
        dict: {
          t8_port_info_id: [],
          t8_prod_info_id: [],
          account_code: []
        },
        SYSDATE: '20200221',
        isdisabled: false,
        rules: {
          tradedate: [
            { required: true, message: '该项不能为空', trigger: 'blur' }
          ],
          startdate: [
            { required: true, message: '该项不能为空', trigger: 'blur' }
          ],
          enddate: [
            { required: true, message: '该项不能为空', trigger: 'blur' }
          ],
          Bill_maintenance: [
            { required: true, message: '该项不能为空', trigger: 'blur' }
          ],
          Pledge_style_Repo1: [
            { required: true, message: '该项不能为空', trigger: 'blur' }
          ],
          Pledge_style_Repo2: [
            { required: true, message: '该项不能为空', trigger: 'blur' }
          ],
          Outright_Repo: [
            { required: true, message: '该项不能为空', trigger: 'blur' }
          ],
          bond_deal2: [
            { required: true, message: '该项不能为空', trigger: 'blur' }
          ],
          total_cost2: [
            { required: true, message: '该项不能为空', trigger: 'change' }
          ],
          t8_sys_portfol_id: [
            { required: true, message: '该项不能为空', trigger: 'change' }
          ],
          t8_prod_info_id: [
            { required: true, message: '该项不能为空', trigger: 'change' }
          ],
          account_code: [
            { required: true, message: '该项不能为空', trigger: 'change' }
          ],
          income_account_code: [
            { required: true, message: '该项不能为空', trigger: 'blur' }
          ],
          income_account_name: [
            { required: true, message: '该项不能为空', trigger: 'blur' }
          ],
          income_opening_account_num: [
            { required: true, message: '该项不能为空', trigger: 'blur' }
          ],
          income_opening_account_name: [
            { required: true, message: '该项不能为空', trigger: 'blur' }
          ]
        },
        form: {
          tradedate: '', // 缴费日期
          startdate: '', // 缴费范围
          enddate: '', // 缴费日期
          Bill_maintenance: '', // 账户维护费
          Pledge_style_Repo1: '', // 质押式回购（单券种）
          Pledge_style_Repo2: '', // 质押式回购（多券种）
          Outright_Repo: '', // 买断式回购
          bond_deal2: '', // 债券买卖
          total_cost2: '', // 总费用
          remark: '', // 备注
          t8_sys_portfol_id: '', // 产品组合
          t8_prod_info_id: '', // 产品/SPV
          prod_principalbln: '', // 产品/SPV余额(元)
          prod_establish_date: '', // 理财产品信息
          prod_end_date: '', // 理财产品信息
          prod_tag_type: '', // 理财产品信息
          trustee_account_code: '', // 理财产品信息
          trustee_account_name: '', // 理财产品信息
          trustee_opening_account_num: '', // 理财产品信息
          broker_code: '', // 券商名称
          account_code: '', // 资金账号
          security_code: '', // 证券账号
          account_name: '', // 资金账户名称
          opening_account_name: '', // 开户行名称
          opening_account_num: '', // 开户行行号
          income_account_code: '', // 收款账号
          income_account_name: '', // 收款户名
          income_opening_account_num: '', // 收款开户行名称
          income_opening_account_name: '' // 收款开户行行号
        }
      }
    },
    mounted() {
      // 初始化调用
      this.init()
    },
    methods: {
      init() {
        this.form.tradedate = this.SYSDATE
        this.load_dict_exeid(this, 'public', 'selectPortfol', 't8_port_info_id')
        this.load_dict_exeid_byParams(this, 'public', { t8_prod_info_id: this.form.t8_prod_info_id, broker_code: this.form.broker_code }, 'selectAccByCondition', 'account_code')
      },
      handleClick(tab, event) {
        console.log(tab, event)
      },
      reset() {
        this.$refs.form.resetFields()
        this.form.tradedate = this.SYSDATE
      },
      getSJSJF(params) {
        var k1 = this.form.Bill_maintenance
        var k2 = this.form.Pledge_style_Repo1
        var k3 = this.form.Pledge_style_Repo2
        var k4 = this.form.Outright_Repo
        var k5 = this.form.bond_deal2

        if(k1 != null && k1 != '' && k2 != null && k2 != '' && k3 != null && k3 != '' && k4 != null && k4 != '' && k5 != null && k5 != '') {
          var k6 = Number(k1) + Number(k2) + Number(k3) + Number(k4) + Number(k5)
          this.form.total_cost2 = Number(k6)
        }
        if(k6 == Number(0)) {
          alert( "总费用不能为0！" )
        }
      },
      portfol_change_fnc() { // 选择了产品组合之后加载产品信息
        this.load_dict_exeid_byParams(this, 'public', { t8_sys_portfol_id: this.form.t8_sys_portfol_id, tradedate: this.form.tradedate }, 'selectProd', 't8_prod_info_id')
      },
      prod_change_fnc(params) {
        if(params.t8_prod_info_id != null) {
          // 起息日
          this.form.prod_establish_date = params.prod_establish_date
          // 到期日
          this.form.prod_end_date = params.prod_end_date
          // 产品类型：1：理财产品  2：SPV
          this.form.prod_tag_type = params.prod_tag_type
          // 托管行账号
          this.form.trustee_account_code = params.trustee_account_code
          // 托管行账号户名
          this.form.trustee_account_name = params.trustee_account_name
          // 托管行账号大额行号
          this.form.trustee_opening_account_num = params.trustee_opening_account_num
          // 托管行账号开户行名称
          this.form.trustee_opening_account_name = params.trustee_opening_account_name
        }
        if(params.t8_prod_info_id == '') {
          return
        }
        // 置空理财产品余额
        this.form.prod_principalbln = ''
        // 非空校验
        if(this.form.tradedate == undefined || this.form.tradedate == ''||
          this.form.t8_prod_info_id == undefined || this.form.t8_prod_info_id == ''){
          return false
        }
        // 调用获取持仓方法
        var dataJson = null
        request({
          loading: true,
          url: 'data/base/comn-query.json?exeid=getProdBalance',
          method: 'post',
          params: { t8_prod_info_id: this.form.t8_prod_info_id, queryDate: this.form.tradedate }
        }).then(rep => {
          dataJson = rep.rows[0]
          if(dataJson != null){
            this.form.prod_principalbln = dataJson.prod_balance
          }
        })
        request({
          loading: true,
          url: 'public/base/comn-query.json?exeid=selectAccByCondition',
          method: 'post',
          params: { t8_prod_info_id: this.form.t8_prod_info_id, account_type: 1, broker_code: null }
        }).then(rep => {
          this['dict']['account_code'] = rep.rows
          if(rep.rows.length == 1) {
            this.form.account_code = rep.rows[0].account_code
            this.form.account_name = rep.rows[0].account_name
            this.form.opening_account_num = rep.rows[0].opening_account_num
            this.form.opening_account_name = rep.rows[0].opening_account_name
            this.form.security_code = rep.rows[0].security_code
          }
        })
      },
      // 提交
      settlement3(params) {
        var _this = this
        this.$refs.form.validate((valid) => {
          if (valid) {
            var checkParams = {}
            var dates = this.form.startdate + "-" + this.form.enddate
            checkParams.tradedate = params.tradedate
            checkParams.t8_sys_portfol_id = params.t8_sys_portfol_id
            checkParams.t8_prod_info_id = params.t8_prod_info_id
            checkParams.date_remake = dates
            checkParams.Bill_maintenance = params.Bill_maintenance
            checkParams.Pledge_style_Repo1 = params.Pledge_style_Repo1
            checkParams.bond_deal2 = params.bond_deal2
            checkParams.remark = params.remark
            checkParams.total_cost2 = params.total_cost2
            checkParams.account_name = params.account_name
            checkParams.account_code = params.account_code
            checkParams.opening_account_num = params.opening_account_num
            checkParams.opening_account_name = params.opening_account_name
            checkParams.income_account_code = params.income_account_code
            checkParams.income_account_name = params.income_account_name
            checkParams.income_opening_account_num = params.income_opening_account_num
            checkParams.income_opening_account_name = params.income_opening_account_name
            checkParams.buttonid = 'M82D310P03B01'
            request({
              loading: true,
              url: 'clearing/accountDeal/TradeFeeSubmit.json',
              method: 'post',
              params: checkParams
            }).then(rep => {
              this.reset()
            })
          } else {
            console.log('表单数据检验没有全部通过！！')
          }
        })
      },
      selectAccount_change_fnc(account_code, params) {
        this.clraeData(account_code)
        if(account_code != '') {
          this.form.account_code = params.account_code
          this.form.account_name = params.account_name
          this.form.opening_account_num = params.opening_account_num
          this.form.opening_account_name = params.opening_account_name
          this.form.security_code = params.security_code
        }
      },
      clraeData(account_code) {
        if(account_code == '' || account_code == undefined){
          this.form.account_code = ''
          this.form.account_name = ''
          this.form.opening_account_num = ''
          this.form.opening_account_name = ''
          this.form.security_code = ''
        }
      },
      /* 通过exeid加载字典 */
      load_dict_exeid(this_object, service_name, exeid, dict) {
        request({
          loading: true,
          url: service_name + '/base/comn-query.json?exeid=' + exeid,
          method: 'post'
        }).then(rep => {
          this_object['dict'][dict] = rep.rows
        })
      },
      /* 通过exeid加载字典 */
      load_dict_exeid_byParams(this_object, service_name, params, exeid, dict) {
        request({
          loading: true,
          url: service_name + '/base/comn-query.json?exeid=' + exeid,
          method: 'post',
          params: params
        }).then(rep => {
          this_object['dict'][dict] = rep.rows
        })
      }
    }
  }
</script>
<style scoped>

</style>
